﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Imaging;

namespace Tanks
{
    public class Explosion
    {
        int frame = 0;
        int Duration = 12;
        Game game = Game.Instance();
        int strength;
        static Bitmap Gr = (Bitmap)Bitmap.FromFile("Explosion.gif", true);
        Cell C;
        public Explosion(Cell c,int s)
        {
            C = c;
            strength = s;
            Gr.SetResolution(game.Resolution, game.Resolution);
        }
        public void Draw(Bitmap canvas)
        {
            if (frame < Duration)
            {
                using (Graphics gr = Graphics.FromImage(canvas))
                {
                    Bitmap CurrFrame;
                    CurrFrame = Gr.Clone(new RectangleF(1, (frame * Gr.Width)+1, Gr.Width-2, Gr.Width-2), Gr.PixelFormat);                
                    gr.DrawImage(CurrFrame, new Point(C.X * game.CellSize, C.Y * game.CellSize));
                    CurrFrame.Dispose();
                }
                frame++;
                if (C.currTank!=null&&frame < 3)
                {
                    C.currTank.Health-=game.rand.Next(strength)+strength;
                }
            }
            else
            {
                game.Expl.Remove(this);
            }
        }
    }
}
